package com.hahehiho.myalbum;

import java.io.File;
import java.io.IOException;

import net.coobird.thumbnailator.Thumbnails;
import net.coobird.thumbnailator.geometry.Positions;

public class Thumbnail {
	public Thumbnail() {
	}

	public static void createImage(String loadFile, String saveFile, boolean isSkipExist) throws IOException {
		File save = new File(saveFile);
		save.getParentFile().mkdirs();
		if(isSkipExist && save.exists()) {
			System.out.println("skip save: " + saveFile);
			return;
		}
		
		System.out.println("createImage load: " + loadFile);
		
		try {
			Thumbnails.of(new File(loadFile)).useExifOrientation(true).crop(Positions.CENTER).size(300, 300).toFile(saveFile);
			System.out.println("createImage save: " + saveFile);
		} catch(OutOfMemoryError e) {
			System.out.println("createImage save fail(oom) skip: " + saveFile);	
		} catch(Throwable t) {			
			System.out.println("createImage save fail: " + saveFile);
			t.printStackTrace();
		}
		
		
	}
	
	public static void main(String[] args) {
		String loadFile = "Y:\\Picture\\NightRider\\Camera_Roll\\IMG_0168.JPG";
		
		String saveFile = loadFile.replace("Y:\\Picture\\", "Y:\\Picture.t\\");
		
		try {
			Thumbnail.createImage(loadFile, saveFile, false);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}